/**
 * 显示新增编辑标签窗口
 */
function deleteTag(email_id,id) {
    layer.closeAll()
    $.ajax({
        url: 'email/deleteBiaoqian',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {
            "emailID":email_id,
            "id":id
        },
        success: function (data) {
           var tag= data.data.tag;
           var emailID= data.data.emailID;
           showBadgeWindow(emailID,tag)
        },
    });
}
function refrashTag() {
    layer.closeAll()
    // 刷新
    tableIns.reload()
}

//
function showBadgeWindow(email_id,tag){

    var biaoqian="";
    if(tag!=null){
        var tags=getTags(tag);
        for(let i in tags){
            biaoqian+= "<span class=\"layui-badge\" style=\"background-color:"+tags[i].color+";color: #0C0C0C\">"+tags[i].title+"</span><a style='text-align: right' onclick=\"deleteTag("+email_id+","+tags[i].id+")\">删除标签</a><br>";
        }
    }
    var html="<div id=\"BadgeWindow\" <div class=\"badge-window\"><div><input type=\"text\" placeholder=\"标签名称\"></div><div>"+
       biaoqian
       +
        "</div><div><a onclick=\"showCreateBadgeWindow("+email_id+")\"><i class=\"icon\">&#xe60f;</i>新增</a><a onclick=\"refrashTag()\">确认</a></div></div></div>";
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        shadeClose: true,
        content: html
    });
}
//
function showCreateBadgeWindow(email_id){
    layer.open({
        btn: ['确定', '取消'],
        type: 1,
        title:'新增标签',
        skin: 'layui-layer-rim', //加上边框
        area: ['420px', '240px'], //宽高
        content: $("#CreateBadgeWindow"),
        btn1:function (index,layero) {
          var title=$("#tagTitle").val();
          var color=$("#tagColor").val();
          addTag(email_id,title,color);
        }
    });
    $("#CreateBadgeWindow").show();
}
function addTag(email_id,title,color){
    layer.closeAll();
    $.ajax({
        url: 'email/addTag',
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {
            "emailID":email_id,
            "title":title,
            "color":color
        },
        success: function (data) {
            var tag= data.data.tag;
            var emailID= data.data.emailID;
            showBadgeWindow(emailID,tag)
        },
    });
}

//xx
$(function(){
    $(document).on('click',".layui-icon-rate-solid",function(){
        if($(this).hasClass('yellow')){
            $(this).removeClass('yellow');
        }else{
            $(this).addClass('yellow');
        }
    });
})
//
function quanxuan(type,t){
    if(type === 'all'){
        if(t.checked){
            $(".email_table input[type=checkbox]").attr("checked","checked");
        }else{
            $(".email_table input[type=checkbox]").removeAttr("checked");
        }
    }else{
        if(t.checked){
            $("input[type=checkbox]["+type+"]").attr("checked","checked");
        }else{
            $("input[type=checkbox]["+type+"]").removeAttr("checked");
        }
    }
}

function showDefineXx(type){
    var url = type?'views/jsp/BasicData/email/defineZdx.jsp':'views/jsp/BasicData/email/defineXinxiang.jsp';
    var area = type?['1000px', '600px']:['600px', '400px'];
    layer.open({
        type: 2
        ,title: false //不显示标题栏
        ,closeBtn: false
        ,area:  area
        ,shade: 0.8
        ,btn: ['确定']
        ,btnAlign: 'c'
        ,moveType: 1 //拖拽模式，0或者1
        ,content: [url,'no']
        ,success: function(layero){


        }
    });
}